Skip to content

Conversation

@mubbi
Copy link
Owner

@mubbi mubbi commented Jul 30, 2025

This pull request introduces several improvements and fixes across the codebase, focusing on type safety, code clarity, and consistency in handling model relationships and data transformations. The changes include stricter type annotations, improved handling of nullable values, and the addition of helper methods for formatting. Below is a breakdown of the most important changes:

Type Safety and Annotations

  • Updated @phpstan-use annotations in multiple models to use \Illuminate\Database\Eloquent\Factories\HasFactory<self> for better type inference and consistency (app/Models/Article.php, app/Models/Category.php, app/Models/User.php, etc.). [1] [2] [3]
  • Added explicit type annotations for Eloquent relationship methods, ensuring type safety for BelongsTo, HasMany, and BelongsToMany relationships (app/Models/Article.php, app/Models/Tag.php, etc.). [1] [2]

Data Transformation Improvements

  • Enhanced nullable handling for date fields in toArray methods by explicitly checking for \DateTimeInterface before calling toISOString (app/Http/Resources/V1/Article/ArticleResource.php, app/Http/Resources/V1/Auth/UserResource.php). [1] [2]
  • Introduced a private helper method formatDateTime in UserResource to encapsulate the logic for formatting date-time values.

Input Validation and Processing

  • Improved input validation in GetCommentsController by explicitly checking if inputs are numeric before casting them to integers, ensuring robustness against invalid input (app/Http/Controllers/Api/V1/Article/GetCommentsController.php).

Middleware Enhancements

  • Added an additional type check in OptionalSanctumAuthenticate middleware to ensure the $accessToken is an instance of PersonalAccessToken before proceeding, enhancing runtime safety (app/Http/Middleware/OptionalSanctumAuthenticate.php).

Code Cleanup and Consistency

  • Removed redundant comments and improved clarity in UserResource by streamlining the logic for iterating over roles and permissions (app/Http/Resources/V1/Auth/UserResource.php).

These changes collectively improve the maintainability, safety, and clarity of the codebase.

mubbi added 3 commits July 31, 2025 02:39
removed all the wrong ignore rules and only added the false positive rules. also created custom
stubs for type definitions
@mubbi mubbi merged commit eea0527 into develop Jul 30, 2025
4 checks passed
@mubbi mubbi deleted the fix/phpstan-types branch July 30, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants